package com.powerManager.sdk.utils;

import java.security.*;
/** 
* <p>Title: encoderByMd5加密算法</p> 
* <p>Description: md5加密</p> 
* <p>Company: hnii</p> 
* @author    LiuC
* @date      2012-8-20 11
*/ 
public class MD5Util {
	public static String encoderByMd5(String str) {
		String s = str;
		if (s == null) {
			return "";
		} else {
			String value = null;
			MessageDigest md5 = null;
			try {
				md5 = MessageDigest.getInstance("MD5");
			} catch (NoSuchAlgorithmException ex) {
			}
			sun.misc.BASE64Encoder baseEncoder = new sun.misc.BASE64Encoder();
			
			try {
				value = baseEncoder.encode(md5.digest(s.getBytes("utf-8")));
			} catch (Exception ex) {
			}
			
			return value;
		}
	}
	public static void main(String[] args) {
		System.out.println(MD5Util.encoderByMd5("test"));
	}
}